package com.woniu.customer.service.impl;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.customer.pojo.OrderbillingsUnit;
import com.woniu.customer.service.OrderbillingsUnitService;
import com.woniu.customer.mapper.OrderbillingsUnitMapper;
import com.woniu.until.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
* @author ajl
* @description 针对表【ecp_clients_orderBillings_unit】的数据库操作Service实现
* @createDate 2023-10-29 16:55:11
*/
@Service
public class OrderbillingsUnitServiceImpl extends ServiceImpl<OrderbillingsUnitMapper, OrderbillingsUnit>
    implements OrderbillingsUnitService{

    @Value("${snowflake.datacenterId}")
    private long datacenterId;
    @Value("${snowflake.workerId}")
    private long workerId;

    @Autowired
    private StringRedisTemplate redisTemplate;
    @Override
    public String addOrderBillings(OrderbillingsUnit orderbillings) {
        Long customerId = IdUtil.getSnowflake(workerId, datacenterId).nextId();
        orderbillings.setCustomerId(customerId);
        save(orderbillings);
        return "新增成功";
    }

    @Override
    public ResponseData<?> addOrderBillingsRedis(OrderbillingsUnit orderbillings) {
        Long customerId = IdUtil.getSnowflake(workerId, datacenterId).nextId();
        orderbillings.setCustomerId(customerId);
        redisTemplate.opsForHash().put(String.valueOf(orderbillings.getBillingUnit()),String.valueOf(orderbillings.getCustomerId()), JSON.toJSONString(orderbillings));
        return new ResponseData<>().ok();
    }
}




